package com.yugao.fintech.libra.shortlink.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yugao.fintech.libra.common.ram.ActionType;
import com.yugao.fintech.libra.common.ram.RamResource;
import com.yugao.fintech.libra.shortlink.model.rqrs.AccessLogBasePageReq;
import com.yugao.fintech.libra.shortlink.model.rqrs.AccessLogResp;
import com.yugao.fintech.libra.shortlink.service.AccessLogService;
import com.yugao.fintech.meheco.core.domain.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/linkAccessLog")
@Tag(name = "短链访问日志")
public class AccessLogController {
    @Autowired
    private AccessLogService accessLogService;

    @Operation(description = "分页-短链访问日志")
    @RamResource(action = "sl:accessLog:query", name = "查询短链访问日志", type = ActionType.READ)
    @GetMapping("/pageAccessLog")
    public ResultVO<IPage<AccessLogResp>> pageLinkAccessLog(@Validated AccessLogBasePageReq query) {
        return ResultVO.success(accessLogService.pageAccessLog(query));
    }

    @Operation(description = "批量删除-短链访问日志")
    @RamResource(action = "sl:accessLog:delete", name = "删除短链访问日志", type = ActionType.WRITE)
    @DeleteMapping("/batchDeleteAccessLog")
    public ResultVO<?> deleteBatch(@RequestParam(value = "ids") List<Long> ids) {
        return ResultVO.success(accessLogService.deleteAccessLogByIds(ids));
    }
}
